<?php
namespace app\apiadmin\controller\doudian;

use app\common\controller\BaseController;
use app\common\utils\curl;
use app\common\utils\Res;
use app\Request;
use Predis\Client;
use think\App;
use think\facade\Db;
use think\facade\Log;

class Doudian extends BaseController
{
    private $grant_type = 'authorization_self';
    private $sign_method = 'hmac-sha256';
    private $_redis;

//    private $shop_id = '22277625';//卡券测试店铺
    private $shop_id = '165563937';//毛毛虫教育

    private $appKey = '7372060210849990182';
    private $appSecret = '79440ea4-0cd8-4036-b820-d05b7db20076';


    public function __construct()
    {
        parent::__construct(app());
        $this->_redis = new Client([
            'scheme' => 'tcp',
            'host' => env('redis.host'),
            'port' => env('redis.port'),
            "password" => env('redis.password'),
            "username" => env('redis.username'),

        ]);
    }

    /**
     * @author: oliver
     * @Description: 抖店字符串排序接口
     * @Date: 2024-06-04 00:00:00
     */
    public function rec_ksort(array &$arr)
    {
        $kstring = true;
        foreach ($arr as $k => &$v) {
            if (!is_string($k)) {
                $kstring = false;
            }
            if (is_array($v)) {
                $this->rec_ksort($v);
            }
        }
        if ($kstring) {
            ksort($arr);
        }
    }

    /**
     * @author: oliver
     * @Description: 抖店获取签名sign接口
     * @Date: 2024-06-04 00:00:00
     */
    public function get_sign($timestamp, $paramJson, $method, $appKey, $appSecret)
    {
        $paramPattern = 'app_key' . $appKey . 'method' . $method . 'param_json' . $paramJson . 'timestamp' . $timestamp . 'v2';
        $signPattern = $appSecret . $paramPattern . $appSecret;
        $sign = hash_hmac("sha256", $signPattern, $appSecret);

        $data['result'] = $sign;
        return $sign;
    }

    /**
     * @author: oliver
     * @Description: 抖店获取access_token接口
     * @Date: 2024-06-04 00:00:00
     */
    public function get_token($timestamp, $appKey, $appSecret, $shopid)
    {
        $accesstoken = false;
        try {
            $accesstoken = $this->_redis->get('doudian:' . $shopid);
        } catch (\Exception $e) {
            Log::channel("doudian")->info("redis读取失败");
        }

        if ($accesstoken != false) {
            $accesstoken = json_decode($accesstoken, true);
        }

        if (!$accesstoken || $accesstoken['expires_in'] < 3600) {
            $a1 = array(
                'code' => '',
                'grant_type' => $this->grant_type,
                'shop_id' => $shopid,
            );
            $paramJson = $this->get_param_json($a1);

            $method = 'token.create';
            $v = '2';
            $sign = $this->get_sign($timestamp, $paramJson, $method, $appKey, $appSecret);

            $url = 'https://openapi-fxg.jinritemai.com/token/create';

            $params = array(
                'app_key' => $appKey,
                'method' => $method,
                'param_json' => $paramJson,
                'timestamp' => $timestamp,
                'v' => '2',
                'sign' => $sign,
                'sign_method' => 'hmac-sha256',
            );

            $accesstoken = Curl::callWebServer($url, $params, 'POST', true, false);
            if ($accesstoken['code'] == 10000) {
                $this->_redis->set('doudian:' . $shopid, json_encode($accesstoken['data']));
                $this->_redis->expire('doudian:' . $shopid, $accesstoken['data']['expires_in'] - 5);
            } else {
                Log::channel("doudian")->info($shopid . "token获取失败" . json_encode($accesstoken));
            }
        }

        return $accesstoken;
    }
    /**
     * @author: oliver
     * @Description: 抖店获取参数json公共方法接口
     * @Date: 2024-06-04 00:00:00
     */
    public function get_param_json($a1)
    {
        $this->rec_ksort($a1); // 对关联数组中的kv，执行排序，需要递归
        $s = json_encode($a1, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); // 重新序列化，确保所有key按字典序排序
        // 加入flag，确保斜杠不被escape，汉字不被escape
        return $s;
    }

    /**
     * @author: oliver
     * @Description: 抖店获取订单详情接口
     * @Date: 2024-06-04 00:00:00
     */
    public function order_detail($shop_order_id, $appKey, $appSecret, $shopid)
    {
        $timestamp = time();
        $v = '2';
        $token_info = $this->get_token($timestamp, $appKey, $appSecret, $shopid);
        $token = $token_info['access_token'];

        $method = 'order.orderDetail';
        $url = 'https://openapi-fxg.jinritemai.com/order/orderDetail';

        $a1 = array(
            'code' => '',
            'grant_type' => $this->grant_type,
            'shop_id' => $shopid,
//            'shop_order_id'=>$_POST['shop_order_id'],
            'shop_order_id' => $shop_order_id,

        );
        $paramJson = $this->get_param_json($a1);
        $sign = $this->get_sign($timestamp, $paramJson, $method, $appKey, $appSecret);
        $params = array(
            'app_key' => $appKey,
            'method' => $method,
            'param_json' => $paramJson,
            'timestamp' => $timestamp,
            'v' => '2',
            'sign' => $sign,
            'sign_method' => $this->sign_method,
            'access_token' => $token,

        );
        Log::channel("doudian")->info("订单详情请求参数：" . json_encode($params));
        $json_obj = Curl::callWebServer($url, $params, 'POST', true, false);

        Log::channel("doudian")->info("订单详情结果：" . json_encode($json_obj));
        $data['paramJson'] = $paramJson;
        $data['sign'] = $sign;
        $data['token'] = $token;
        $data['result'] = $json_obj;
        return $json_obj;
//        return Res::ok($data);
    }

    /**
     * @author: oliver
     * @Description: 抖店获取订单详情接口
     * @Date: 2024-06-04 00:00:00
     */
    public function order_detail_json($shop_order_id)
    {
//        $shop_order_id = $_GET['shop_order_id'];
        //shop_order_id  测试数据  shop_order_id
        $appKey = $this->appKey;
        $appSecret = $this->appSecret;
        $timestamp = time();
        $v = '2';
        $token_info = $this->get_token($timestamp);
        $token = $token_info['access_token'];

        $method = 'order.orderDetail';
        $url = 'https://openapi-fxg.jinritemai.com/order/orderDetail';

        $a1 = array(
            'code' => '',
            'grant_type' => $this->grant_type,
            'shop_id' => $this->shop_id,
//            'shop_order_id'=>$_POST['shop_order_id'],
            'shop_order_id' => $shop_order_id,

        );
        $paramJson = $this->get_param_json($a1);
        $sign = $this->get_sign($timestamp, $paramJson, $method);
        $params = array(
            'app_key' => $appKey,
            'method' => $method,
            'param_json' => $paramJson,
            'timestamp' => $timestamp,
            'v' => '2',
            'sign' => $sign,
            'sign_method' => $this->sign_method,
            'access_token' => $token,

        );
        $json_obj = Curl::callWebServer($url, $params, 'POST', true, false);

        $data['paramJson'] = $paramJson;
        $data['sign'] = $sign;
        $data['token'] = $token;
        $data['result'] = $json_obj;
        return Res::ok($data);
    }

    /**
     * @author: oliver
     * @Description: 抖店获取订单列表接口
     * @Date: 2024-06-04 00:00:00
     */
    public function order_list()
    {
        $appKey = $this->appKey;
        $appSecret = $this->appSecret;
        $timestamp = time();
        $v = '2';
        $token_info = $this->get_token($timestamp);
        $token = $token_info['access_token'];

        $method = 'order.searchList';
        $url = 'https://openapi-fxg.jinritemai.com/order/searchList';

        $a1 = array(
            'code' => '',
            'grant_type' => $this->grant_type,
            'shop_id' => $this->shop_id,
//            'size'=>10,
            //            'page'=>20,
            //            'create_time_start'=>'1714552691',
            //            'create_time_end'=>'1717144691',
            'size' => $_POST['size'],
            'page' => $_POST['page'],
            'create_time_start' => $_POST['create_time_start'],
            'create_time_end' => $_POST['create_time_end'],

        );
        $paramJson = $this->get_param_json($a1);
        $sign = $this->get_sign($timestamp, $paramJson, $method);
        $params = array(
            'app_key' => $appKey,
            'method' => $method,
            'param_json' => $paramJson,
            'timestamp' => $timestamp,
            'v' => '2',
            'sign' => $sign,
            'sign_method' => $this->sign_method,
            'access_token' => $token,

        );
        $json_obj = Curl::callWebServer($url, $params, 'POST', true, false);

        $data['paramJson'] = $paramJson;
        $data['sign'] = $sign;
        $data['token'] = $token;
        $data['result'] = $json_obj;
        return Res::ok($data);
    }

    /**
     * @author: crg
     * @Description: 抖店发布商品接口
     * @Date: 2024-06-04 00:00:00
     */
    public  function addV2(){
        $appKey = $this->appKey;
        $appSecret = $this->appSecret;
        $timestamp =time();
        $v= '2';
        $token_info = $this->get_token($timestamp);
        $token = $token_info['data']['access_token'];

        $method = 'product.addV2';
        $url = 'https://openapi-fxg.jinritemai.com/product/addV2';

        // Spec_price数组要求
        $pr = array(
            'spec_detail_name1'=>'红色',
            'stock_num'=>11,
            'price'=>10,
        );
        $spec_prices_v2 = array(
            'sku_status' => true,
            'price' => 10,
            'sku_type' => 0
        );
        $sell_properties = array(
            'property_name' => '颜色',
            'value_name'=>'黑色',

        );
        $spec_prices_v2['sell_properties'] = $sell_properties;
        $str = json_encode($pr);
        $a1 = array(
            'code'=>'',
            'grant_type'=>$this->grant_type,
            'shop_id'=>$this->shop_id,
            //商品信息
            'product_type'=> 0,
            'category_leaf_id'=> 26220,
            'name'=> '测试书籍test测试书籍',
            'pic'=> 'https://p3-aio.ecombdimg.com/obj/ecom-shop-material/NRJahsQb_m_34257878fa1cffa6506cfecedc2b96a9_sx_217456_www619-619|https://p3-aio.ecombdimg.com/obj/ecom-shop-material/NRJahsQb_m_34257878fa1cffa6506cfecedc2b96a9_sx_217456_www619-619|https://p3-aio.ecombdimg.com/obj/ecom-shop-material/NRJahsQb_m_34257878fa1cffa6506cfecedc2b96a9_sx_217456_www619-619',
            'description'=> 'https://p3-aio.ecombdimg.com/obj/ecom-shop-material/NRJahsQb_m_34257878fa1cffa6506cfecedc2b96a9_sx_217456_www619-619|https://p3-aio.ecombdimg.com/obj/ecom-shop-material/NRJahsQb_m_34257878fa1cffa6506cfecedc2b96a9_sx_217456_www619-619|https://p3-aio.ecombdimg.com/obj/ecom-shop-material/NRJahsQb_m_34257878fa1cffa6506cfecedc2b96a9_sx_217456_www619-619',
            'reduce_type'=> 2,
            'freight_id'=> 0,
            'mobile'=> 40012345,
            'commit'=> true,
            'specs'=> '颜色|红色,黑色,',
            'spec_prices' => $str,
            'package_sku' => '',
            'spec_prices_v2' => $spec_prices_v2,
            'standard_brand_id' => '1854396311',
            'delivery_delay_day' => 2,
            'supply_price' => 10
        );
        $paramJson =  $this->get_param_json($a1);
        $sign = $this->get_sign($timestamp,$paramJson,$method);

        $params = array(
            'app_key'=>$appKey,
            'method'=>$method,
            'param_json'=>$paramJson,
            'timestamp'=>$timestamp,
            'v'=>'2',
            'sign'=>$sign,
            'sign_method'=> $this->sign_method,
            'access_token'=>$token,
        );
        $json_obj = Curl::callWebServer($url,$params,'POST',true,false);

        $data['paramJson'] = $paramJson;
        $data['sign'] = $sign;
        $data['token'] = $token;
        $data['result'] = $json_obj;
        return Res::ok($data);
    }

    /**
     * @author: crg
     * @Description: 抖店获取商品类目
     * @Date: 2024-06-04 00:00:00
     */
    public function getShopCategory()
    {
        $appKey = $this->appKey;
        $appSecret = $this->appSecret;
        $timestamp = time();
        $v = '2';
        $token_info = $this->get_token($timestamp);
        $token = $token_info['access_token'];

        $method = 'shop.getShopCategory';
        $url = 'https://openapi-fxg.jinritemai.com/shop/getShopCategory';
        $a1 = array(
            'code' => '',
            'grant_type' => $this->grant_type,
            'shop_id' => $this->shop_id,
            'cid' => 0,
        );
        $paramJson = $this->get_param_json($a1);
        $sign = $this->get_sign($timestamp, $paramJson, $method);

        $params = array(
            'app_key' => $appKey,
            'method' => $method,
            'param_json' => $paramJson,
            'timestamp' => $timestamp,
            'v' => '2',
            'sign' => $sign,
            'sign_method' => $this->sign_method,
            'access_token' => $token,
        );
        $json_obj = Curl::callWebServer($url, $params, 'POST', true, false);

        $data['paramJson'] = $paramJson;
        $data['sign'] = $sign;
        $data['token'] = $token;
        $data['result'] = $json_obj;
        return Res::ok($data);
    }

    /**
     * @author: oliver
     * @Description: 抖店 卡券核销 接口
     * @Date: 2024-06-04 00:00:00
     */
    public function coupons_verify()
    {
        $param = $this->request->param();
        $appKey = $this->appKey;
        $appSecret = $this->appSecret;
        $shopid = $this->shop_id;
        $cert_no = $param['cert_no'];
        $timestamp = time();
        $v = '2';
        $token_info = $this->get_token($timestamp, $appKey, $appSecret, $shopid);
        $token = $token_info['access_token'];

        $method = 'coupons/verifyV2';
        $url = 'https://openapi-fxg.jinritemai.com/coupons/verifyV2';

        $a1 = array(
            'code' => '',
            'grant_type' => $this->grant_type,
            'shop_id' => $this->shop_id,
            //此处是接口特殊参数
            'cert_no' => $cert_no,
        );
        $paramJson = $this->get_param_json($a1);
        $sign = $this->get_sign($timestamp, $paramJson, $method, $appKey, $appSecret);
        $params = array(
            'app_key' => $appKey,
            'method' => $method,
            'param_json' => $paramJson,
            'timestamp' => $timestamp,
            'v' => '2',
            'sign' => $sign,
            'sign_method' => $this->sign_method,
            'access_token' => $token,

        );
        $json_obj = Curl::callWebServer($url, $params, 'POST', true, false);

        $data['paramJson'] = $paramJson;
        $data['sign'] = $sign;
        $data['token'] = $token;
        $data['result'] = $json_obj;
        return Res::ok($data);
    }

    /**
     * @author: oliver
     * @Description: 抖店 卡券取消核销 接口
     * @Date: 2024-06-04 00:00:00
     */
    public function coupons_cancelVerify()
    {
        $appKey = $this->appKey;
        $appSecret = $this->appSecret;
        $timestamp = time();
        $v = '2';
        $token_info = $this->get_token($timestamp);
        $token = $token_info['access_token'];

        $method = 'coupons/cancelVerify';
        $url = 'https://openapi-fxg.jinritemai.com/coupons/cancelVerify';

        $a1 = array(
            'code' => '',
            'grant_type' => $this->grant_type,
            'shop_id' => $this->shop_id,
            //此处是接口特殊参数

            'cert_no' => $_POST['cert_no'],

        );
        $paramJson = $this->get_param_json($a1);
        $sign = $this->get_sign($timestamp, $paramJson, $method);
        $params = array(
            'app_key' => $appKey,
            'method' => $method,
            'param_json' => $paramJson,
            'timestamp' => $timestamp,
            'v' => '2',
            'sign' => $sign,
            'sign_method' => $this->sign_method,
            'access_token' => $token,

        );
        $json_obj = Curl::callWebServer($url, $params, 'POST', true, false);

        $data['paramJson'] = $paramJson;
        $data['sign'] = $sign;
        $data['token'] = $token;
        $data['result'] = $json_obj;
        return Res::ok($data);
    }

    /**
     * @author: oliver
     * @Description: 抖店 回调地址 接口
     * @Date: 2024-06-04 00:00:00
     */
    public function notify()
    {
        $jsonData = file_get_contents('php://input');
        Log::channel("doudian")->info("收到回调数据：" . $jsonData);

        $b = json_decode($jsonData, true);
        $tag = $b[0]['tag'];
//        $tag = "101";

        $orderinfo = json_decode($b[0]['data'], true);
        $p_id = $orderinfo['p_id'];
        $shopid = $orderinfo['shop_id'];
        //查询抖店密钥
        $this->_getDoudianCfg($appKey, $appSecret, $sms_account, $sign, $template_id, $shopid);

        //创建订单成功
        if ($tag == "101") {
            //非卡券商品跳过
            if ($orderinfo['order_type'] !== 5) {
                Log::channel("doudian")->info("非卡券商品：" . json_encode($orderinfo));
                echo json_encode(array("code" => 0, "msg" => "success"));
                exit;
            }

            Log::channel("doudian")->info("卡券商品继续处理");

            $order_detail = $this->order_detail($p_id, $appKey, $appSecret, $shopid);
            Log::channel("doudian")->info("订单详情：" . json_encode($order_detail));

            $param['sms_account'] = $sms_account;
            $param['sign'] = $sign;
            $param['template_id'] = $template_id;
            //http://a.mmctsg.com/L/k/x/1/o/
            $param['template_param'] = '{"code":"' . $p_id . '","url":"a.mmctsg.com/L/k/x/1/o/' . $p_id . '"}';
            $param['post_tel'] = $order_detail['data']['shop_order_detail']['encrypt_post_tel'];
            Log::channel("doudian")->info("开始同步卡券");
            $sync = $this->syncV2($p_id, $appKey, $appSecret, $shopid,$param['post_tel']);
            
            //查询短信配置
            // $sms_account = config('doudian.' . $shopid, 'sms_account');
            // $sign = config('doudian.' . $shopid, 'sign');
            // $template_id = config('doudian.' . $shopid, 'template_id');
            
            Log::channel("doudian")->info("短信内容：" . json_encode($param));
            $send = $this->sms_send($param, $appKey, $appSecret, $shopid);
            //存储抖店短信记录
            $sms = array();
            $sm = json_encode($send);
            $sms['order_no'] = $p_id;
            $sms['coupons_no'] = $sync['cert_no'];
            $sms['send_time'] = date('Y-m-d H:i:s');
            $sms['state'] = 1;
            $sms['message_id'] = $sm['message_id'];
            $sms['create_time'] = date('Y-m-d H:i:s');
            Log::channel('doudian')->info('存储抖店短信发送记录：' . json_encode($sms));
            $d['remark'] =  '存储抖店短信发送记录'.json_encode($sms).'***';
            DB::table('xh_siyu_user_remark')->save($d);
            DB::table('xh_sms_send')->save($sms);
        }
        if ($tag == '200') { //客户发起退款的时候触发的回调
            $order_detail = $this->order_detail($p_id, $appKey, $appSecret, $shopid);
            if ($order_detail['data']['shop_order_detail']['order_type'] !== 5) {
                Log::channel("doudian")->info("非卡券商品售后单：" . json_encode($orderinfo));
                echo json_encode(array("code" => 0, "msg" => "success"));
                exit;
            }
            $aftersale_id = json_decode($b[0]['data'], true)['aftersale_id'];
            Log::channel("doudian")->info("售后单回调，aftersale_id：" . $aftersale_id);
            $this->refund($appKey, $appSecret, $shopid, $aftersale_id);
        }

        echo json_encode(array("code" => 0, "msg" => "success"));
    }
    /*public function db_order_detail($p_id)
    {
    $d['remark'] = '我是走进了db_order_detail方法 $p_id是' . $p_id . '***';
    DB::table('xh_siyu_user_remark')->save($d);
    $data1 = $this->order_detail($p_id);

    $data['order_num'] = $p_id;
    $data['time'] = date("Y-m-d H:i:s");
    $data['app_id'] = $data1['data']['shop_order_detail']['app_id'];
    $data['tel'] = $data1['data']['shop_order_detail']['encrypt_post_tel'];
    $data['total_fee'] = $data1['data']['shop_order_detail']['order_amount'];
    $data['dy_openid'] = $data1['data']['shop_order_detail']['doudian_open_id'];
    $data['pay_time'] = date('Y-m-d H:i:s', $data1['data']['shop_order_detail']['create_time']);

    $orderlist[0]['i_id'] = $data1['data']['shop_order_detail']['sku_order_list'][0]['product_id_str']; //外教课
    $orderlist[0]['manager'] = '抖音-毛毛虫教育';
    $orderlist[0]['out_trade_no'] = $p_id;
    $orderlist[0]['order_num'] = $p_id;
    $orderlist[0]['fee'] = $data1['data']['shop_order_detail']['order_amount'];
    $orderlist[0]['shop_id'] = $this->shop_id;
    $orderlist[0]['time'] = time(); //时间戳
    $orderlist[0]['tel'] = $data1['data']['shop_order_detail']['mask_post_tel']; //
    $orderlist[0]['paymethod'] = $data1['data']['shop_order_detail']['pay_type']; //
    $orderlist[0]['pay_time'] = strtotime(date('Y-m-d H:i:s', $data1['data']['shop_order_detail']['create_time'])); //
    $orderlist[0]['product_id'] = $data1['data']['shop_order_detail']['sku_order_list'][0]['product_id_str']; //
    $orderlist[0]['province'] = $data1['data']['shop_order_detail']['mask_post_addr']['province']['name']; //
    $orderlist[0]['city'] = $data1['data']['shop_order_detail']['mask_post_addr']['city']['name']; //
    $orderlist[0]['county'] = $data1['data']['shop_order_detail']['mask_post_addr']['town']['name']; //
    $orderlist[0]['addr'] = $data1['data']['shop_order_detail']['mask_post_addr']['detail']; //
    $data11 = $this->addXXHOrder($orderlist);
    $data12 = $this->addUnionOrder($orderlist);

    $d['remark'] = '$data 的json数据 是' . json_encode($data) . '***';
    DB::table('xh_siyu_user_remark')->save($d);

    //        //往数据库插入数据
    DB::table('xh_order_2')->save($data);

    return $orderlist;
    }*/
    public function test()
    {
        //tag 101 ---支付完成   100---订单创建

//        $b =  json_decode($a, true);
        //        $data['tag'] = $b[0]['tag'];
        //        $data['msg_id'] = $b[0]['msg_id'];
        //        $data['data_origin'] = $b[0]['data'];
        //        $data['biz'] = json_decode($b[0]['data'],true)['biz'];
        //        $data['create_time'] = json_decode($b[0]['data'],true)['create_time'];
        //        $data['order_status'] = json_decode($b[0]['data'],true)['order_status'];
        //        $data['s_ids'] = json_decode($b[0]['data'],true)['s_ids'];
        //        $data['p_id'] = json_decode($b[0]['data'],true)['p_id'];
//        $p_id = '6930644604755908239';

//        $order_detail = $this->db_order_detail($p_id);
//                $data1 = $this->get_token(time());
//                $d['remark'] =  '我是测试token'.json_encode($data1);
//                DB::table('xh_siyu_user_remark')->save($d);
                $param['sms_account'] = '7d49c08a';
                $param['sign'] = '毛毛虫教育';
                $param['template_id'] = 'ST_7d5c2512';
                $param['template_param'] =  '{"code":"933540732530","url":"a.mmctsg.com/L/k/o/MjMyMTM5"}';
//                $param['post_tel'] ='$$jFxHUMcbAfI4FpJVNrdQp1jVILI4ZUiWfP1OIKSvvv6ZxzKBnWtvURi8nsc3b5z4dotn1dUSiyADfA3grpaSz17/PdeIfmNEOCdmBzyo2nfVV+E=*CgYIASAHKAESPgo8CtW2Zk7xQQsRf7S9bdExcNImdxsLk4aSonrNA/BhmBIw4I2rBCyCxoX4l1Lo8KUX12mT9g5WSdayH6h3GgA=$1$$';
                $param['post_tel'] ='17772611308';
                $appKey = $this->appKey;
                $appSecret = $this->appSecret;
                $shopid = $this->shop_id;
                $a = $this->sms_send($param,$appKey, $appSecret, $shopid);
                
                $d['remark'] =  '我执行了发送短信操作'.'***';
                DB::table('xh_siyu_user_remark')->save($d);

//        $sync = $this->syncV2($p_id);

//        $d['remark'] =  '我执行了卡券同步操作'.json_encode($sync).'***';
        //        DB::table('xh_siyu_user_remark')->save($d);

//        dump($sync);
//        return Res::ok($sync);
    }

    /*public function addUnionOrder($orderlist)
    {
    $a = array();
    $a['operator'] = '抖音-毛毛虫教育';
    $a['manager'] = '抖音-毛毛虫教育';
    $a['laiyuan'] = 20;
    $a['i_id'] = $orderlist[0]['product_id'];

    $course = \think\facade\Db::connect('mysql2')
    ->table('un_english_course_goodsid')->where(array('product_id' => "3688277236940669376"))
    ->find();

    $a['tel'] = '';
    $a['courseid'] = $course['courseid'];
    $a['del'] = 0;
    $a['time'] = $orderlist[0]['pay_time'];
    $a['price'] = $orderlist[0]['fee'] / 100;
    $a['pay_state'] = 1;
    $a['fee'] = $orderlist[0]['fee'] / 100;
    $a['refund_fee'] = 0;

    $a['items'] = '英语课程费';
    $a['goods_detail'] = '[{"id":8,"fee":"' . ($orderlist[0]['fee'] / 100) . '.00","name":"\u82f1\u8bed\u8bfe\u7a0b\u8d39"}]';
    $a['params'] = '{"remark":"\u8d2d\u4e70\u82f1\u8bed\u8bfe\u7a0b","price":"' . ($orderlist[0]['fee'] / 100) . '.00","courseid":"' . $course['courseid'] . '",tichengtype":0,"ticheng":"0.00","tichengmoney":0.000}';
    $a['order_num'] = $orderlist[0]['order_num'] . '';
    $a['out_trade_no'] = $orderlist[0]['out_trade_no'] . '';
    $a['result'] = '';
    $a['flag'] = 9;
    $a['pay_time'] = $orderlist[0]['pay_time'];
    $a['refund_time'] = 0;
    $a['weapp_openid'] = '';
    $a['ticheng'] = 0;
    $a['tichengmoney'] = 0;
    $a['tichengtype'] = 0;
    $a['province'] = $orderlist[0]['province'];
    $a['city'] = $orderlist[0]['city'];
    $a['county'] = $orderlist[0]['county'];
    $a['addr'] = $orderlist[0]['addr'];
    $a['shop_id'] = $this->shop_id;

    if ($this->getCourseGuiZe() == "1") { //买一送一
    if ($course['courseid'] == 17) {
    $a['waijiao'] = '19,20';
    } else if ($course['courseid'] == 20) {
    $a['waijiao'] = '17,19';
    } else {
    $a['waijiao'] = '0';
    }
    } else {
    if ($course['courseid'] == 17) {
    $a['waijiao'] = '19';
    } else {
    $a['waijiao'] = '0';
    }
    }

    $aa = \think\facade\Db::connect('mysql2')
    ->table('un_english_course_order')->save($a);

    $c['order_num'] = $orderlist[0]['order_num'] . '';
    $c['time'] = $orderlist[0]['pay_time'];
    $c['courseid'] = $course['courseid'];
    $c['fee'] = $orderlist[0]['fee'] / 100;
    $c['laiyuan'] = $a['laiyuan'];
    $c['del'] = 0;
    $cc = \think\facade\Db::connect('mysql2')
    ->table('un_english_course_ordernum')->save($c);
    }*/

    /*public function addXXHOrder($orderlist)
    {
    $qiyeid = '1';
    $c = array();
    $e = array();
    foreach ($orderlist as $k => $a) {
    //            $product = M('course_product', 'xh_', C('DB_CONFIG_XIAOXUEHUA'))->where(array('product_id' => array('like', '%' . $a['i_id'] . '%')))->find();
    $where1[] = ['product_id', 'like', '%' . $a['i_id'] . '%'];
    $product = DB::table('xh_course_product')->where($where1)->find();

    $qiyeid = $product['qiyeid'];
    //            $laiyuan = M('app_laiyuan', 'xh_', C('DB_CONFIG_XIAOXUEHUA'))->where(array('name' => $a['manager']))->find();
    $where2[] = ['name', '=', $a['manager']];
    $laiyuan = DB::table('xh_app_laiyuan')->where($where2)->find();
    $b = array();
    $b['courseid'] = $product['courseid'];
    //            $b['dy_openid'] = '';
    //            $b['dy_union'] = '';
    $b['out_order_no'] = $a['out_trade_no'];
    //            $b['out_trade_no'] = $a['out_trade_no'];
    $b['order_num'] = $a['order_num'];
    $b['total_fee'] = $a['fee'] * 100;
    $b['pingtai'] = $laiyuan['pingtaiid']; //1:抖音
    $b['laiyuan'] = $laiyuan['id'];
    $b['app_id'] = $a['shop_id'];
    $b['time'] = date('Y-m-d H:i:s', $a['time']);
    $b['del'] = 0;
    if ($a['tel']) {
    $b['tel'] = $a['tel'];
    } else {
    $b['tel'] = '';
    }

    $b['order_status'] = 1;
    $b['pay_method'] = $a['paymethod'];
    $b['pay_state'] = 1;
    $b['pay_time'] = date('Y-m-d H:i:s', $a['pay_time']);
    $b['jinrufangshi'] = '';

    //售卖逻辑
    if ($this->getCourseGuiZe() == "1") { //买一送一
    if ($product['courseid'] == 17) {
    $b['waijiao'] = '19,20';
    } else if ($product['courseid'] == 20) {
    $b['waijiao'] = '17,19';
    } else {
    $b['waijiao'] = '0';
    }
    } else {
    if ($product['courseid'] == 17) {
    $b['waijiao'] = '19';
    } else {
    $b['waijiao'] = '0';
    }
    }

    $c[] = $b;

    //存储id临时表
    $d = array();
    $d['courseid'] = $b['courseid'];
    $d['order_num'] = $b['order_num'];
    $d['out_order_no'] = $b['out_order_no'];
    $d['state'] = 1;
    $d['tel'] = $b['tel'];
    $d['time'] = $b['time'];
    $d['app_id'] = $b['app_id'];
    //            $d['qiyeid'] = $qiyeid['id'];
    $d['qiyeid'] = $qiyeid;
    $d['pingtai'] = $laiyuan['pingtaiid']; //1:抖音
    $d['laiyuan'] = $laiyuan['id'];

    $e[] = $d;

    }
    //        M('ordernum','xh_',C('DB_CONFIG_XIAOXUEHUA'))->addAll($e);
    foreach ($e as $v) {
    DB::table('xh_ordernum')->save($v);
    }

    //        M('order_'.$qiyeid, 'xh_', C('DB_CONFIG_XIAOXUEHUA'))->addAll($c);

    foreach ($c as $v) {
    DB::table('xh_order_1')->save($v);
    }

    //给订单打短码标签
    //        if($e){
    //            foreach ($e as $k => $v) {
    //                dabiaoqian($v);
    //            }
    //        }

    //预分配
    //         $order_nums = array_column($orderlist,'order_num');
    //        xiaoxuehua_yufenpei($order_nums);

    }*/

    public function getCourseGuiZe()
    {

//        $data = M('common')->where(array('keys'=>'course_guize'))->find();
        $where[] = ['keys', '=', 'course_guize'];
        $data = DB::table('xh_common')->where($where)->find();
        return $data['values'];
    }
    /**
     * @author: oliver
     * @Description: 订单退款接口
     * @Date: 2024-06-04 00:00:00
     */
    public function refund($appKey, $appSecret, $shopid, $aftersaleid)
    {
        $timestamp = time();
        $token_info = $this->get_token($timestamp, $appKey, $appSecret, $shopid);
        $token = $token_info['access_token'];
//        $method = 'afterSale/operate';
        //        $url = 'https://openapi-fxg.jinritemai.com/afterSale/operate';
        //        $method = 'sendHome/afterSale/operateAfterSale';
        //        $url = 'https://openapi-fxg.jinritemai.com/sendHome/afterSale/operateAfterSale';
        $method = 'afterSale/CancelSendGoodsSuccess';
        $url = 'https://openapi-fxg.jinritemai.com/afterSale/CancelSendGoodsSuccess';
        $certno = '';
        $order_id = '';

        $a1 = array(
            'code' => '',
            'grant_type' => $this->grant_type,
            'shop_id' => $shopid,
            'op_time' => time(),
            'aftersale_id' => $aftersaleid,

        );
        $paramJson = $this->get_param_json($a1);
        $sign = $this->get_sign($timestamp, $paramJson, $method, $appKey, $appSecret);

        $params = array(
            'app_key' => $appKey,
            'method' => $method,
            'param_json' => $paramJson,
            'timestamp' => $timestamp,
            'v' => '2',
            'sign' => $sign,
            'sign_method' => $this->sign_method,
            'access_token' => $token,
        );
        $json_obj = Curl::callWebServer($url, $params, 'POST', true, false);
        Log::channel('doudian')->info('退款处理结果：' . json_encode($json_obj));

        $data['paramJson'] = $paramJson;
        $data['sign'] = $sign;
        $data['token'] = $token;
        $data['result'] = $json_obj;
        return Res::ok($data);
    }

    public function after_sale_list()
    {
//        /afterSale/List
        $appKey = $this->appKey;
        $timestamp = time();
        $token_info = $this->get_token($timestamp);
        $token = $token_info['access_token'];

        $method = 'afterSale/List';
        $url = 'https://openapi-fxg.jinritemai.com/afterSale/List';
        $certno = '';
        $order_id = '';

        $a1 = array(
            'code' => '',
            'grant_type' => $this->grant_type,
            'shop_id' => $this->shop_id,

//            'type'=> 121,//
            //            'items' => array(
            //                'aftersale_id'=>'6930642293882164879',//售后单号
            //            ),
            //           'store_id' => $this->shop_id,
            //           'operate_type' => 201,
            //           'after_sale_id' => $_POST['after_sale_id'],
            'page' => 100,
            'size' => 100,
            'order_id' => $_POST['order_id'],

        );
        $paramJson = $this->get_param_json($a1);
        $sign = $this->get_sign($timestamp, $paramJson, $method);

        $params = array(
            'app_key' => $appKey,
            'method' => $method,
            'param_json' => $paramJson,
            'timestamp' => $timestamp,
            'v' => '2',
            'sign' => $sign,
            'sign_method' => $this->sign_method,
            'access_token' => $token,
        );
        $json_obj = Curl::callWebServer($url, $params, 'POST', true, false);

        $data['paramJson'] = $paramJson;
        $data['sign'] = $sign;
        $data['token'] = $token;
        $data['result'] = $json_obj;
        return Res::ok($data);
    }

    /**
     * @author: oliver
     * @Description: 抖店短信 签名申请 接口
     * @Date: 2024-06-04 00:00:00
     */
    public function sms_send($param, $appKey, $appSecret, $shopid)
    {
        $timestamp = time();
        $v = '2';
        $token_info = $this->get_token($timestamp, $appKey, $appSecret, $shopid);
        $token = $token_info['access_token'];
        $e['remark'] =  '我执行了发送短信操作333'.$token.'***';
        DB::table('xh_siyu_user_remark')->save($e);
//        echo $sms; die;
        $method = 'sms.send';
        $url = 'https://openapi-fxg.jinritemai.com/sms/send';

        $a1 = array(
            'code' => '',
            'grant_type' => $this->grant_type,
            'shop_id' => $shopid,
            //此处是接口特殊参数

//            'sms_account'=>$_POST['sms_account'],
            //            'sign'=>$_POST['sign'],
            //            'template_id'=>$_POST['template_id'],
            //            'template_param'=>$_POST['template_param'],
            //            'post_tel'=>$_POST['post_tel'],

            'sms_account' => $param['sms_account'],
            'sign' => $param['sign'],
            'template_id' => $param['template_id'],
            'template_param' => $param['template_param'],
            'post_tel' => $param['post_tel'],

        );
        $paramJson = $this->get_param_json($a1);
        $sign = $this->get_sign($timestamp, $paramJson, $method, $appKey, $appSecret);
        $params = array(
            'app_key' => $appKey,
            'method' => $method,
            'param_json' => $paramJson,
            'timestamp' => $timestamp,
            'v' => '2',
            'sign' => $sign,
            'sign_method' => $this->sign_method,
            'access_token' => $token,

        );
        $json_obj = Curl::callWebServer($url, $params, 'POST', true, false);

        Log::channel('doudian')->info('短信发送结果：' . json_encode($json_obj));

        $data['paramJson'] = $paramJson;
        $data['sign'] = $sign;
        $data['token'] = $token;
        $data['result'] = $json_obj;
        return $json_obj;
    }

    /**
     * @author: crg
     * @Description: 卖家在平台卖出券后同步卡券信息
     * @Date: 2024-06-04 00:00:00
     */
    public function syncV2($param, $appKey, $appSecret, $shopid, $posttel)
    {
        $timestamp = time();
        $token_info = $this->get_token($timestamp, $appKey, $appSecret, $shopid);
        $token = $token_info['access_token'];

        $method = 'coupons.syncV2';
        $url = 'https://openapi-fxg.jinritemai.com/coupons/syncV2';
        // 获取当前的时间戳和随机数
        $randomNum = mt_rand(100000, 999999);
        $prefix = 'kq';
        // 组合订单号前缀和序列号
        $number = $prefix . $timestamp . str_pad($randomNum, 6, '0', STR_PAD_LEFT);
        $date = date('Y-m-d H:i:s');
        $cert_list = array(
            'cert_link' => env('Live.live_host'),
            'cert_no' => $number,
            'grant_time' => $date,
        );
        $a1 = array(
            'code' => '',
            'grant_type' => $this->grant_type,
            'shop_id' => $shopid,
            'order_id' => $param,
            'cert_list' => $cert_list,
            'status' => 2,
        );
        $paramJson = $this->get_param_json($a1);
        $sign = $this->get_sign($timestamp, $paramJson, $method, $appKey, $appSecret);

        $params = array(
            'app_key' => $appKey,
            'method' => $method,
            'param_json' => $paramJson,
            'timestamp' => $timestamp,
            'v' => '2',
            'sign' => $sign,
            'sign_method' => $this->sign_method,
            'access_token' => $token,
        );
        Log::channel('doudian')->info('卡券同步参数：' . json_encode($params));
        $json_obj = Curl::callWebServer($url, $params, 'POST', true, false);
        Log::channel('doudian')->info('卡券同步结果：' . json_encode($json_obj));
        
        $can = array();
        $can['shop_id'] = $shopid;
        $can['post_tel'] = $posttel;
        $can['order_no'] = $param;
        $can['coupons_no'] = $number;
        $can['state'] = 1;
        $can['create_time'] = date('Y-m-d H:i:s', $timestamp);
        Log::channel('doudian')->info('卡券订单回调存储信息：' . json_encode($can));
        $d['remark'] =  '卡券订单回调存储信息'.json_encode($can).'***';
        DB::table('xh_siyu_user_remark')->save($d);
        $id = DB::table('xh_coupons')->insertGetId($can);

        $data['cert_no'] = $number;
        $data['paramJson'] = $paramJson;
        $data['sign'] = $sign;
        $data['token'] = $token;
        $data['result'] = $json_obj;
        return $data;
    }

    /**
     * @author: oliver
     * @Description: 券码废弃接口
     * @Date: 2024-06-04 00:00:00
     */
    public function coupons_abandon()
    {
        $appKey = $this->appKey;
        $timestamp = time();
        $token_info = $this->get_token($timestamp);
        $token = $token_info['access_token'];
        $method = 'coupons.list';
        $url = 'https://openapi-fxg.jinritemai.com/coupons/list';
        $certno = '';
        $order_id = '';

        $a1 = array(
            'code' => '',
            'grant_type' => $this->grant_type,
            'shop_id' => $this->shop_id,
            'cert_no' => $_POST['cert_no'],
            'cert_type' => 1,
        );
        $paramJson = $this->get_param_json($a1);
        $sign = $this->get_sign($timestamp, $paramJson, $method);

        $params = array(
            'app_key' => $appKey,
            'method' => $method,
            'param_json' => $paramJson,
            'timestamp' => $timestamp,
            'v' => '2',
            'sign' => $sign,
            'sign_method' => $this->sign_method,
            'access_token' => $token,
        );
        $json_obj = Curl::callWebServer($url, $params, 'POST', true, false);

        $data['paramJson'] = $paramJson;
        $data['sign'] = $sign;
        $data['token'] = $token;
        $data['result'] = $json_obj;
        return Res::ok($data);
    }

    /**
     * @author: crg
     * @Description: 券码查询接口
     * @Date: 2024-06-04 00:00:00
     */
    public function couponsList()
    {
        $appKey = $this->appKey;
        $timestamp = time();
        $token_info = $this->get_token($timestamp);
        $token = $token_info['access_token'];
        $method = 'coupons.list';
        $url = 'https://openapi-fxg.jinritemai.com/coupons/list';
        $certno = '';
        $order_id = '';

        $a1 = array(
            'code' => '',
            'grant_type' => $this->grant_type,
            'shop_id' => $this->shop_id,
            'order_id' => $_POST['order_id'],
            'cert_no' => $_POST['cert_no'],
            'cert_type' => 1,
        );
        $paramJson = $this->get_param_json($a1);
        $sign = $this->get_sign($timestamp, $paramJson, $method);

        $params = array(
            'app_key' => $appKey,
            'method' => $method,
            'param_json' => $paramJson,
            'timestamp' => $timestamp,
            'v' => '2',
            'sign' => $sign,
            'sign_method' => $this->sign_method,
            'access_token' => $token,
        );
        $json_obj = Curl::callWebServer($url, $params, 'POST', true, false);

        $data['paramJson'] = $paramJson;
        $data['sign'] = $sign;
        $data['token'] = $token;
        $data['result'] = $json_obj;
        return Res::ok($data);
    }

    /**
     * @author: crg
     * @Description: 根据类目id获取可选品牌
     * @Date: 2024-06-04 00:00:00
     */
    public function brandList()
    {
        $appKey = $this->appKey;
        $timestamp = time();
        $token_info = $this->get_token($timestamp);
        $token = $token_info['access_token'];

        $method = 'brand.list';
        $url = 'https://openapi-fxg.jinritemai.com/brand/list';
        $a1 = array(
            'code' => '',
            'grant_type' => $this->grant_type,
            'shop_id' => $this->shop_id,
            'category_id' => 26220,
        );
        $paramJson = $this->get_param_json($a1);
        $sign = $this->get_sign($timestamp, $paramJson, $method);

        $params = array(
            'app_key' => $appKey,
            'method' => $method,
            'param_json' => $paramJson,
            'timestamp' => $timestamp,
            'v' => '2',
            'sign' => $sign,
            'sign_method' => $this->sign_method,
            'access_token' => $token,
        );
        $json_obj = Curl::callWebServer($url, $params, 'POST', true, false);

        $data['paramJson'] = $paramJson;
        $data['sign'] = $sign;
        $data['token'] = $token;
        $data['result'] = $json_obj;
        return Res::ok($data);
    }

    public function handsync()
    {
        $flag = $this->request->param('flag');
        $shopid = $this->request->param('shopid');
        $danhao = $this->request->param('danhao');
        $param['post_tel'] = '15833650367';
        $this->_getDoudianCfg($appKey, $appSecret, $sms_account, $sign, $template_id, $shopid);
        if ($flag == 'sync') {
            $sync = $this->syncV2($danhao, $appKey, $appSecret, $shopid,$param['post_tel']);
            dump($sync);
            exit;
        }
        if ($flag == 'sms') {
            $param['sms_account'] = $sms_account;
            $param['sign'] = $sign;
            $param['template_id'] = $template_id;
            //http://a.mmctsg.com/L/k/x/1/o/
            $param['template_param'] = '{"code":"' . $danhao . '","url":"a.mmctsg.com/L/k/x/1/o/' . $danhao . '"}';
            $param['post_tel'] = '15833650367';
            $sms = $this->sms_send($param, $appKey, $appSecret, $shopid);
            exit;
        }

        $sync = $this->syncV2($danhao, $appKey, $appSecret, $shopid,$param['post_tel']);
        dump($sync);

        $param['sms_account'] = $sms_account;
        $param['sign'] = $sign;
        $param['template_id'] = $template_id;
        //http://a.mmctsg.com/L/k/x/1/o/
        $param['template_param'] = '{"code":"' . $danhao . '","url":"a.mmctsg.com/L/k/x/1/o/' . $danhao . '"}';
        $param['post_tel'] = '15833650367';
        $sms = $this->sms_send($param, $appKey, $appSecret, $shopid);
        dump($sms);
    }

    public function handrefund()
    {
        $id = $this->request->get('id');
        $this->_getDoudianCfg($appKey, $appSecret, $sms_account, $sign, $template_id, '165563937');
        $res = $this->refund($appKey, $appSecret, '165563937', $id);
        dump($res);
    }

    private function _getDoudianCfg(&$appKey, &$appSecret, &$sms_account, &$sign, &$template_id, $shopid)
    {
        $appKey = config('doudian.' . $shopid . '.appKey');
        $appSecret = config('doudian.' . $shopid . '.appSecret');
        //查询短信配置
        $sms_account = config('doudian.' . $shopid . '.sms_account');
        $sign = config('doudian.' . $shopid . '.sign');
        $template_id = config('doudian.' . $shopid . '.template_id');
    }


    /**
     * @author: crg
     * @Description: 根据短信id获取短信信息
     * @Date: 2024-06-04 00:00:00
     */
    public function sendResult()
    {
        $appKey = $this->appKey;
        $timestamp = time();
        $appSecret = $this->appSecret;
        $shopid = $this->shop_id;
        $token_info = $this->get_token($timestamp, $appKey, $appSecret, $shopid);
        $token = $token_info['data']['access_token'];

        $method = 'sms.sendResult';
        $url = 'https://openapi-fxg.jinritemai.com/sms/sendResult';
        $a1 = array(
            'code' => '',
            'grant_type' => $this->grant_type,
            'shop_id' => $this->shop_id,
            'from_time' => 0,
            'to_time' => 26220,
            'sms_account' => '7d49c08a',
            'message_id' => 26220,
            'page' => 100,
            'size' => 1,
        );
        $paramJson = $this->get_param_json($a1);
        $sign = $this->get_sign($timestamp, $paramJson, $method, $appKey, $appSecret);

        $params = array(
            'app_key' => $appKey,
            'method' => $method,
            'param_json' => $paramJson,
            'timestamp' => $timestamp,
            'v' => '2',
            'sign' => $sign,
            'sign_method' => $this->sign_method,
            'access_token' => $token,
        );
        $json_obj = Curl::callWebServer($url, $params, 'POST', true, false);

        $data['paramJson'] = $paramJson;
        $data['sign'] = $sign;
        $data['token'] = $token;
        $data['result'] = $json_obj;
        return Res::ok($data);
    }


    /**
     * @author: crg
     * @Description: 短信回执
     * @Date: 2024-06-04 00:00:00
     */
    public function sms_notify()
    {
        $d['remark'] =  '进入短信回执录';
        $a = DB::table('xh_siyu_user_remark')->save($d);
        
        $jsonData = file_get_contents('php://input');
        $c['remark'] =  '短信回执录:'.$jsonData;
        $a = DB::table('xh_siyu_user_remark')->save($c);
        $jsonInfo = json_decode($jsonData,true);
        $c['remark'] =  '短信回执message_id:'.$jsonInfo['message_id'];
        $a = DB::table('xh_siyu_user_remark')->save($c);
        //回调短信id查询订单信息
        $smsSend = DB::table('xh_sms_send')->where(array('message_id'=>'1'))->find();
        $c['remark'] =  '存储短信数据:'.$smsSend;
        $a = DB::table('xh_siyu_user_remark')->save($c);
        //        if ($jsonInfo['status_code'] == 0) {
//            //订单号查询xh_order_1信息更改短信发送状态
////            $xhorder = DB::table('xh_order_1')->where(array('order_num'=>$smsSend[0]['order_no']))->find();
//            $order = array(
//                'send_sms' => 1,
//                'receive_sms' => $jsonInfo['recv_time'],
//                'receive_sms_time' => date('Y-m-d H:i:s')
//            );
//            DB::table('xh_order_1')->where(array('order_num'=>$smsSend[0]['order_no']))->update($order);
//            //更改存储抖店短信记录短信状态
//            DB::table('xh_order_1')->where(array('id'=>$smsSend['id']))->update(array('state'=>3));
//        }else {
//            //更改存储抖店短信记录短信状态
//            DB::table('xh_order_1')->where(array('id'=>$smsSend['id']))->update(array('state'=>2));
//        }
        return Res::ok($a);
    }


    /**
     * @author: crg
     * @Description: 自主发送抖店短信
     * @Date: 2024-06-04 00:00:00
     */
    public function mysend()
    {
        $param = $this->request->param();
        $appKey = $this->appKey;
        $appSecret = $this->appSecret;
        $shopid = $this->shop_id;
        $post_tel = $param['post_tel'];
        $timestamp = time();
        $v = '2';
        $token_info = $this->get_token($timestamp, $appKey, $appSecret, $shopid);
        $token = $token_info['access_token'];
        $method = 'sms.send';
        $url = 'https://openapi-fxg.jinritemai.com/sms/send';
        $a1 = array(
            'code' => '',
            'grant_type' => $this->grant_type,
            'shop_id' => $shopid,
            'sms_account' => '7d49c08a',
            'sign' => '毛毛虫教育',
            'template_id' => 'ST_7d5c2512',
            'template_param' => '{"code":"933540732530","url":"a.mmctsg.com/L/k/o/MjMyMTM5"}',
            'post_tel' => $post_tel,
        );
        $paramJson = $this->get_param_json($a1);
        $sign = $this->get_sign($timestamp, $paramJson, $method, $appKey, $appSecret);
        $params = array(
            'app_key' => $appKey,
            'method' => $method,
            'param_json' => $paramJson,
            'timestamp' => $timestamp,
            'v' => '2',
            'sign' => $sign,
            'sign_method' => $this->sign_method,
            'access_token' => $token,

        );
        $json_obj = Curl::callWebServer($url, $params, 'POST', true, false);

        Log::channel('doudian')->info('自主短信发送结果：' . json_encode($json_obj));

        $data['paramJson'] = $paramJson;
        $data['sign'] = $sign;
        $data['token'] = $token;
        $data['result'] = $json_obj;
        return Res::ok($data);
    }

}
